/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.hk.sys.web.adv;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.hk.sys.entity.adv.HkCategoryQuery;
import com.thinkgem.jeesite.modules.hk.sys.service.adv.HkCategoryQueryService;

/**
 * 分类查询Controller
 * @author 罗天文
 * @version 2018-06-01
 */
@Controller
@RequestMapping(value = "${adminPath}/sys/adv/hkCategoryQuery")
public class HkCategoryQueryController extends BaseController {

	@Autowired
	private HkCategoryQueryService hkCategoryQueryService;
	
	@ModelAttribute
	public HkCategoryQuery get(@RequestParam(required=false) String id) {
		HkCategoryQuery entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = hkCategoryQueryService.get(id);
		}
		if (entity == null){
			entity = new HkCategoryQuery();
		}
		return entity;
	}
	
	@RequiresPermissions("sys:adv:hkCategoryQuery:view")
	@RequestMapping(value = {"list", ""})
	public String list(HkCategoryQuery hkCategoryQuery, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<HkCategoryQuery> page = hkCategoryQueryService.findPage(new Page<HkCategoryQuery>(request, response), hkCategoryQuery); 
		model.addAttribute("page", page);
		return "hk/sys/adv/hkCategoryQueryList";
	}

	@RequiresPermissions("sys:adv:hkCategoryQuery:view")
	@RequestMapping(value = "form")
	public String form(HkCategoryQuery hkCategoryQuery, Model model) {
		model.addAttribute("hkCategoryQuery", hkCategoryQuery);
		return "hk/sys/adv/hkCategoryQueryForm";
	}

	@RequiresPermissions("sys:adv:hkCategoryQuery:edit")
	@RequestMapping(value = "save")
	public String save(HkCategoryQuery hkCategoryQuery, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, hkCategoryQuery)){
			return form(hkCategoryQuery, model);
		}
		hkCategoryQueryService.save(hkCategoryQuery);
		addMessage(redirectAttributes, "保存分类查询成功");
		return "redirect:"+Global.getAdminPath()+"/sys/adv/hkCategoryQuery/?repage";
	}
	
	@RequiresPermissions("sys:adv:hkCategoryQuery:edit")
	@RequestMapping(value = "delete")
	public String delete(HkCategoryQuery hkCategoryQuery, RedirectAttributes redirectAttributes) {
		hkCategoryQueryService.delete(hkCategoryQuery);
		addMessage(redirectAttributes, "删除分类查询成功");
		return "redirect:"+Global.getAdminPath()+"/sys/adv/hkCategoryQuery/?repage";
	}

}